<?php
    include_once "../../inc/config.inc.php";
    include_once '../../inc/mysql.inc.php';
    include_once '../inc/tool.inc.php';

    $template["title"] = "子版块修改";
    $template["keyword"] = "子版块修改";
    $template["description"] = "子版块修改";

    $link = connect();

    if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
        skip("son_module.php", "error", "id参数错误！");  
    }

    $query = "select * from kuse_son_module where id = {$_GET['id']}";
    $result = execute($link, $query);
    if(!mysqli_num_rows($result)){
        skip("son_module.php", "error", "这条子版块信息不存在！");
    }
    $data = mysqli_fetch_assoc($result);

    if(isset($_POST['submit'])){
        $check_flag = "update";

        // 验证填写信息是否正确
        include_once '../inc/check_son_module.inc.php';
        
        $query = "update kuse_son_module set father_module_id='{$_POST['father_module_id']}', module_name='{$_POST['module_name']}', info='{$_POST['info']}', member_id='{$_POST['member_id']}', sort={$_POST['sort']} where id ={$_GET['id']}";
        execute($link, $query);
        // 验证是否插入成功
        if(mysqli_affected_rows($link)==1){
            skip("son_module.php", "ok", "恭喜你，修改成功！");
        }else{
            skip("son_module.php", "error", "对不起，修改失败，请重试！");
        }
    }
    
?>
<?php include_once "../inc/header.inc.php";?>
<div id="main">
    <div class="title">子版块修改 - <?php echo $data['module_name']?></div>
    <form method="post">
        <table class="au">
            <tr>
                <td>所属父版块</td>
                <td>
                    <select name="father_module_id">
                        <option value='0'>======请选择父版块======</option>
                        <?php
                        $query="select * from kuse_father_module";
                        $result_father = execute($link, $query);
                        while($data_father = mysqli_fetch_assoc($result_father)){
                            if($data['father_module_id'] == $data_father['id']){
                                echo "<option selected='selected' value='{$data_father['id']}'>{$data_father['module_name']}</option>";
                            }else{
                                echo "<option value='{$data_father['id']}'>{$data_father['module_name']}</option>";
                            }
                        }
                        ?>
                    </select>
                </td>
                <td>必须选择一个所属的父版块</td>
            </tr>
            <tr>
                <td>版块名称</td>
                <td><input name="module_name" value=<?php echo $data['module_name'] ?> type="text" /></td>
                <td>版块名称不得为空，最大不能超过66个字符</td>
            </tr>
            <tr>
                <td>版块简介</td>
                <td><textarea name="info"><?php echo $data['info'] ?></textarea></td>
                <td>版块简介不得多于255个字符</td>
            </tr>
            <tr>
                <td>版主</td>
                <td>
                    <select name="member_id">
                        <option value='0'>======请选择一个会员作为版主======</option>
                    </select>
                </td>
                <td>你可以在这边选一个会员作为版主</td>
            </tr>
            <tr>
                <td>排序</td>
                <td><input name="sort" value='0' value=<?php echo $data['sort'] ?> type="text" /></td>
                <td>填写一个数字即可</td>
            </tr>
        </table>

        <input type="submit" class="btn" name="submit" value="修改">
    </form>
</div>

<?php include_once "../inc/footer.inc.php";?>